package edu.my.service;

import edu.my.dao.BookDao;
import edu.my.model.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("saleService")
public class SaleService {

    @Autowired
    BookDao bookDao;

    /*@Autowired
    @Qualifier(value = "bookDaoImpl")
    public void setBookdao(BookDao bookdao) {
        this.bookdao = bookdao;
    }
     */

    @Transactional
    public void insert(Book book){
        bookDao.insertBook(book);
    }

    @Transactional
    public void onSale(float sale){
        List<Book> bookList = bookDao.findAll();
        for(Book b : bookList){
            b.setPrice(b.getPrice() * sale);
            bookDao.modifyBook(b);
        }
    }
}
